# $Id: PKGBUILD 88189 2013-04-13 14:28:43Z kkeen $
# Maintainer: Kyle Keen <keenerd@gmail.com>
# Contributor: Chris Brannon <chris@the-brannons.com>
# Contributor : Douglas Soares de Andrade <dsa@aur.archlinux.org>

pkgbase=ipython2
_pkgbase=ipython
pkgname=(ipython2 ipython2-docs)
pkgver=0.13.2
pkgrel=1
arch=('any')
url="http://ipython.org"
license=('Modified BSD')
makedepends=('python2') # for setup.py
source=("http://archive.ipython.org/release/$pkgver/ipython-$pkgver.tar.gz")
md5sums=('ead3b7eb70c653b537fb9d96d71b8b2a')

package_ipython2() {
  pkgdesc="An enhanced Interactive Python2 shell."
  depends=('python2' 'python2-distribute')
  optdepends=("wxpython: needed for ipythonx and ipython-wx"
              "twisted: networking-related tasks"
              "python2-foolscap: for IPython's parallel computing features"
              "python2-pexpect: for irunner"
              "python2-nose: if you want to run IPython's test suite"
              "python2-pyqt: for ipython-qtconsole"
              "python2-sip: for ipython-qtconsole"
              "python2-pygments: for ipython-qtconsole"
              "python2-pyzmq: for ipython-qtconsole"
              "python2-tornado: for ipython notebook")

  cd "$srcdir/$_pkgbase-$pkgver"

  python2 setup.py install --prefix=/usr --root="$pkgdir" --optimize=0
  rm -rf "$pkgdir/usr/share/doc"
  find "$pkgdir" -name '*.py' -print0 |xargs -0 \
    sed -i -e 's,^#!/usr/bin/env python$,#!/usr/bin/env python2,' \
    -e 's,^#!/usr/bin/python$,#!/usr/bin/python2,'
  find "$pkgdir/" -name '*.pyc' -delete

  # hack to get around ipython collision
  cd "$pkgdir/usr/share/man/man1/"
  mv ipcluster.1    ipcluster2.1
  mv ipcontroller.1 ipcontroller2.1
  mv ipengine.1     ipengine2.1
  mv iplogger.1     iplogger2.1
  mv ipython.1      ipython2.1
  mv irunner.1      irunner2.1
  mv pycolor.1      pycolor2.1
  cd "$pkgdir/usr/bin/"
  mv ipcluster         ipcluster2
  mv ipcontroller      ipcontroller2
  mv ipengine          ipengine2
  mv iplogger          iplogger2
  mv iptest            iptest2
  mv ipython           ipython2
  mv irunner           irunner2
  mv pycolor           pycolor2
}

package_ipython2-docs() {
  pkgdesc='Documentation and examples for IPython2'

  cd "$srcdir/$_pkgbase-$pkgver"

  python2 setup.py install --prefix=/usr --root="$pkgdir"
  rm -rf "$pkgdir/usr/lib" "$pkgdir/usr/bin" "$pkgdir/usr/share/man"

 find "$pkgdir" -name '*.py' -print0 |xargs -0 \
    sed -i -e 's,^#!/usr/bin/env python$,#!/usr/bin/env python2,' \
    -e 's,^#!/usr/bin/python$,#!/usr/bin/python2,'

  # This seems wrong.  We're running setup.py for both
  # packages, and removing different things in each.
  mv "$pkgdir/usr/share/doc/ipython/" "$pkgdir/usr/share/doc/ipython2/"
}

